{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1ff3a9b9",
   "metadata": {},
   "source": [
    "· 日期：2023-3-16\\week04(周四)\n",
    "\n",
    "· 课程：API、机器学习与人工智能\n",
    "\n",
    "· 记录人：林荣烽"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f43f4e9",
   "metadata": {},
   "source": [
    "## 本周内容\n",
    ">1. 人脸识别概念和基础\n",
    "\n",
    ">2. 人脸识别应用\n",
    "\n",
    ">3. 人脸识别实践-face++\n",
    ">>1. 人脸检测\n",
    ">>2. 人脸比对+人脸搜索\n",
    ">>>1. 人脸集合创建\n",
    ">>>2. 人脸"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbba615f",
   "metadata": {},
   "source": [
    "## 人脸识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0e314fee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'request_id': '1678938282,2361766b-f761-49fe-917a-fed3d724cd01',\n",
       " 'time_used': 281,\n",
       " 'faces': [{'face_token': 'e2b44df042c25b87c2bc06c7b12a5896',\n",
       "   'face_rectangle': {'top': 445, 'left': 619, 'width': 270, 'height': 270},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 22},\n",
       "    'smile': {'value': 53.629, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.004,\n",
       "     'disgust': 0.012,\n",
       "     'fear': 0.004,\n",
       "     'happiness': 93.644,\n",
       "     'neutral': 0.983,\n",
       "     'sadness': 0.013,\n",
       "     'surprise': 5.34},\n",
       "    'beauty': {'male_score': 88.409, 'female_score': 88.543}}}],\n",
       " 'image_id': 'IsZmJsMjbziWhZWlV9eFgA==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('yangying.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"image_base64\":img,\n",
    "    \"api_key\":\"RP1WIFtQV8G-QYys8ZmGfAJSD4Wx2CfV\",\n",
    "    \"api_secret\":\"9N1MABzFOJg6Soc5d4OuNEYj8cpT4ZWx\",\n",
    "    \"return_attributes\":\"gender,age,smiling,emotion,beauty\"\n",
    "}\n",
    "\n",
    "request_url = request_url \n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "\n",
    "print (response.status_code)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4502ff91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'request_id': '1678938841,53039b1b-97b5-4ce7-954e-97efd39ddb92',\n",
       " 'time_used': 214,\n",
       " 'faces': [{'face_token': 'bc27cd971edad40077dc5e57ca19d7f0',\n",
       "   'face_rectangle': {'top': 266, 'left': 426, 'width': 183, 'height': 183},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 20},\n",
       "    'smile': {'value': 3.266, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.11,\n",
       "     'disgust': 0.11,\n",
       "     'fear': 0.11,\n",
       "     'happiness': 0.517,\n",
       "     'neutral': 7.322,\n",
       "     'sadness': 10.408,\n",
       "     'surprise': 81.422},\n",
       "    'beauty': {'male_score': 76.321, 'female_score': 78.097}}}],\n",
       " 'image_id': 'XwC8h+bONFVcF806m0P4Rg==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('yushuxin.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"image_base64\":img,\n",
    "    \"api_key\":\"RP1WIFtQV8G-QYys8ZmGfAJSD4Wx2CfV\",\n",
    "    \"api_secret\":\"9N1MABzFOJg6Soc5d4OuNEYj8cpT4ZWx\",\n",
    "    \"return_attributes\":\"gender,age,smiling,emotion,beauty\"\n",
    "}\n",
    "\n",
    "request_url = request_url \n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "\n",
    "print (response.status_code)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0dbf6b01",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'request_id': '1678939107,00a462d1-e0aa-49b5-ab35-998d24d44d8c',\n",
       " 'time_used': 263,\n",
       " 'faces': [{'face_token': 'cc0c4a747e38b8835cafcaca3d31e1bc',\n",
       "   'face_rectangle': {'top': 305, 'left': 332, 'width': 291, 'height': 291},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 31},\n",
       "    'smile': {'value': 0.339, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.022,\n",
       "     'disgust': 0.009,\n",
       "     'fear': 0.055,\n",
       "     'happiness': 0.031,\n",
       "     'neutral': 98.226,\n",
       "     'sadness': 1.602,\n",
       "     'surprise': 0.056},\n",
       "    'beauty': {'male_score': 89.607, 'female_score': 91.675}}}],\n",
       " 'image_id': 'CbMMbZO/eJD5pmxFJm6csQ==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('luoyizhou.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"image_base64\":img,\n",
    "    \"api_key\":\"RP1WIFtQV8G-QYys8ZmGfAJSD4Wx2CfV\",\n",
    "    \"api_secret\":\"9N1MABzFOJg6Soc5d4OuNEYj8cpT4ZWx\",\n",
    "    \"return_attributes\":\"gender,age,smiling,emotion,beauty\"\n",
    "}\n",
    "\n",
    "request_url = request_url \n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "\n",
    "print (response.status_code)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7e7faa00",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'request_id': '1679461957,1a387c71-b2ad-44c2-83d2-04b3a43d6c16',\n",
       " 'time_used': 293,\n",
       " 'faces': [{'face_token': '77371958179b97d1a5d030aeb78da087',\n",
       "   'face_rectangle': {'top': 422, 'left': 344, 'width': 401, 'height': 401},\n",
       "   'attributes': {'gender': {'value': 'Male'},\n",
       "    'age': {'value': 20},\n",
       "    'smile': {'value': 0.096, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 2.386,\n",
       "     'disgust': 0.932,\n",
       "     'fear': 0.029,\n",
       "     'happiness': 24.149,\n",
       "     'neutral': 71.199,\n",
       "     'sadness': 1.277,\n",
       "     'surprise': 0.029},\n",
       "    'beauty': {'male_score': 79.882, 'female_score': 81.015}}}],\n",
       " 'image_id': 'ZhXWjsiTWuzcu0LKZTpZOA==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('zhanglinghe.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"image_base64\":img,\n",
    "    \"api_key\":\"RP1WIFtQV8G-QYys8ZmGfAJSD4Wx2CfV\",\n",
    "    \"api_secret\":\"9N1MABzFOJg6Soc5d4OuNEYj8cpT4ZWx\",\n",
    "    \"return_attributes\":\"gender,age,smiling,emotion,beauty\"\n",
    "}\n",
    "\n",
    "request_url = request_url \n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "\n",
    "print (response.status_code)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14cdc195",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
